/**
 * @overview 创建垂直路宽
 * @author dengqiang
 * @description 鲸云CgsWall
 * @update  2022.03.26
 */
class GCgsImageWall {
  constructor() {
    window.GCgsImageWallArray = []
  }

  //新增单个垂直路宽
  add(paramObj) {
    const { name, parentName, option } = paramObj
    const materialUtilImage = new CgsMaterialUtil()
    //材质对象
    const imageMaterialPropertyImage = materialUtilImage.createMaterialProperty('Image', {
      image: option.imgUrl,
    })
    const wallImage = new CgsWall({
      positions: [
        [option.pos.lng - 0.00003, option.pos.lat, option.pos.height + 5],
        [option.pos.lng + 0.00003, option.pos.lat, option.pos.height + 5],
      ],
      diffHeight: option.labelHeight || 6,
      fillColor: 'rgba(0, 0, 255, 0)',
      material: imageMaterialPropertyImage,
      materialState: true,
      outlineColor: 'rgba(0, 0, 0, 0)',
    })
    //添加
    const imageWallObject = {
      name: name,
      parentName: parentName,
      imageWall: wallImage,
    }
    window.GCgsImageWallArray.push(imageWallObject)
    window.map.addFeature(wallImage)
  }

  //根据name移除单个垂直路宽
  removeByName(name) {
    window.GCgsImageWallArray.forEach((item, index) => {
      if (item.name == name) {
        window.map.removeFeature(item.imageWall)
        window.GCgsImageWallArray.splice(index, 1)
      }
    })
  }

  //根据parentName移除一批垂直路宽
  removeByPatName(parentName) {
    const length = window.GCgsImageWallArray.length
    for (let i = length - 1; i >= 0; i--) {
      if (window.GCgsImageWallArray[i].parentName == parentName) {
        window.map.removeFeature(window.GCgsImageWallArray[i].imageWall)
        window.GCgsImageWallArray.splice(i, 1)
      }
    }
  }

  //移除所有垂直路宽
  removeAll() {
    window.GCgsImageWallArray.forEach((item) => {
      window.map.removeFeature(item.imageWall)
    })
    window.GCgsImageWallArray = []
  }

  //根据name控制单个垂直路宽的显隐
  setVisibleByName(name, boolean) {
    window.GCgsImageWallArray.forEach((item) => {
      if (item.name == name) {
        item.imageWall.setVisible(boolean)
      }
    })
  }

  //根据parentName控制一批垂直路宽的显隐
  setVisibleByPatName(parentName, boolean) {
    window.GCgsImageWallArray.forEach((item) => {
      if (item.parentName == parentName) {
        item.imageWall.setVisible(boolean)
      }
    })
  }
}

export default GCgsImageWall
